
// <copyright file="DelegateBasedComparer.cs" company="Subhadra Software Solutions">
//   
// </copyright>
// <summary>
//   The delegate based comparer.
// </summary>

namespace SubhadraSolutions.Sharp.Utils
{
    using System;
    using System.Collections.Generic;

    /// <summary>
    /// The delegate based comparer.
    /// </summary>
    /// <typeparam name="T">
    /// </typeparam>
    public class DelegateBasedComparer<T> : IComparer<T>
    {
        #region Fields

        /// <summary>
        /// The comparison.
        /// </summary>
        private readonly Comparison<T> comparison;

        #endregion Fields

        // Methods
        #region Constructors and Finalizers

        /// <summary>
        /// Initializes a new instance of the <see cref="DelegateBasedComparer{T}"/> class.
        /// </summary>
        /// <param name="comparison">
        /// The comparison.
        /// </param>
        public DelegateBasedComparer(Comparison<T> comparison)
        {
            this.comparison = comparison;
        }

        #endregion Constructors and Finalizers

        #region Public Methods and Operators

        /// <summary>
        /// The compare.
        /// </summary>
        /// <param name="x">
        /// The x.
        /// </param>
        /// <param name="y">
        /// The y.
        /// </param>
        /// <returns>
        /// The <see cref="int"/>.
        /// </returns>
        public int Compare(T x, T y)
        {
            return this.comparison(x, y);
        }

        #endregion Public Methods and Operators
    }
}